package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.SetmealService;
import com.sky.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.DomainEvents;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author wangqi
 * @date 2024/1/2 09:01
 */
@RestController
@RequestMapping("/admin")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    @PostMapping("/setmeal")
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO){
        log.info("添加套餐：{}",setmealDTO);
        setmealService.addSetmeal(setmealDTO);
        return Result.success();
    }

    @GetMapping("/setmeal/page")
    public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO){
        log.info("套餐分页查询：{}",setmealPageQueryDTO);
        PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO);

        log.info("套餐查询的结果：{}",pageResult);
        return Result.success(pageResult);
    }

    @GetMapping("/setmeal/{id}")
    public Result<SetmealVO> findSetmealById(@PathVariable Long id){
        log.info("根据套餐id查询套餐详情：{}",id);
        SetmealVO setmealVO = setmealService.findSetmealById(id);
        return Result.success(setmealVO);
    }

    @PutMapping("/setmeal")
    public Result update(@RequestBody SetmealDTO setmealDTO){
        log.info("修改套餐数据：{}",setmealDTO);
        setmealService.update(setmealDTO);
        return Result.success();
    }

    @DeleteMapping("/setmeal")
    public Result delete(Long[] ids){
        log.info("删除套餐：{}", Arrays.toString(ids));
        setmealService.delete(ids);
        return Result.success();
    }

    @PostMapping("/setmeal/status/{status}")
    public Result status(@PathVariable Integer status, Long id){
        log.info("修改套餐的状态：status={},id={}",status,id);
        setmealService.update(status,id);
        return Result.success();
    }
}
